package com.qingcloud.task.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingcloud.task.mapper.TaskRelationMapper;
import com.qingcloud.task.model.TaskRelation;
import com.qingcloud.task.service.TaskRelationService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 任务关联信息表 服务实现类
 * </p>
 *
 * @author zhengjibin
 * @since 2022-01-20
 */
@Service
public class TaskRelationServiceImpl extends ServiceImpl<TaskRelationMapper, TaskRelation> implements TaskRelationService {

    @Override
    public void saveRelation(List<String> relationIds, Integer relationType, Long taskId) {
        if (CollectionUtils.isEmpty(relationIds)){
            return;
        }
        List<TaskRelation> list = new ArrayList<>(relationIds.size());
        relationIds.forEach( id -> {
            TaskRelation relation = new TaskRelation();
            relation.setTaskId(taskId);
            relation.setRelationId(id);
            relation.setRelationType(relationType);
            list.add(relation);
        });
        saveBatch(list);
    }
}
